﻿using Logistics.Manager;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Logistics
{
    public partial class frmSAPDataDetail : Form
    {
        public string l_tc_owr001;
        public string l_tc_owr002;
        private readonly TC_OWS_FILE _ows_file;
        ListViewColumnSorter lvwColumnSorter = new ListViewColumnSorter();
        public frmSAPDataDetail()
        {
            InitializeComponent();
            this.listInfo.ListViewItemSorter = lvwColumnSorter;
            ImageList imgList = new ImageList();
            imgList.ImageSize = new Size(1, 20);//分别是宽和高
            listInfo.SmallImageList = imgList;
            _ows_file = new TC_OWS_FILE();
        }

        public frmSAPDataDetail(string _tc_owr001, string _tc_owr002) : this()
        {
            l_tc_owr001 = _tc_owr001;
            l_tc_owr002 = _tc_owr002;
        }

        private void listInfo_ColumnClick(object sender, ColumnClickEventArgs e)
        {
            if (e.Column == lvwColumnSorter.SortColumn)
            {
                if (lvwColumnSorter.Order == SortOrder.Ascending)
                {
                    lvwColumnSorter.Order = SortOrder.Descending;
                }
                else
                {
                    lvwColumnSorter.Order = SortOrder.Ascending;
                }
            }
            else
            {
                lvwColumnSorter.SortColumn = e.Column;
                lvwColumnSorter.Order = SortOrder.Ascending;
            }
            this.listInfo.Sort();
        }

        private void frmSAPDataDetail_Load(object sender, EventArgs e)
        {
            var list = _ows_file.GetDetail(l_tc_owr001, l_tc_owr002);
            foreach (var item in list)
            {
                AddListviewItem(item);
            }
        }

        private void AddListviewItem(Model.TC_OWS_FILE model)
        {
            ListViewItem item = null;
            item = new ListViewItem();
            item.Tag = model.TC_OWS000;
            item.SubItems.Add(model.TC_OWS001);
            item.SubItems.Add(model.TC_OWS002);
            item.SubItems.Add(model.TC_OWS003);
            item.SubItems.Add(model.TC_OWS004);
            item.SubItems.Add(model.TC_OWS005);
            item.SubItems.Add(model.ima02);
            item.SubItems.Add(model.TC_OWS006);
            item.SubItems.Add(model.TC_OWS007);
            item.SubItems.Add(model.TC_OWS008);
            item.SubItems.Add(model.TC_OWS009);
            item.SubItems.Add(model.TC_OWS010);
            item.SubItems.Add(model.TC_OWS011);
            item.SubItems.Add(model.TC_OWS012);
            item.SubItems.Add(model.TC_OWS013);
            item.SubItems.Add(model.TC_OWS014);
            if (model.TC_OWS019.HasValue)
                item.SubItems.Add(model.TC_OWS019.Value.ToString("yyyy-MM-dd"));
            else
                item.SubItems.Add("");
            item.SubItems.Add(model.TC_OWS022);

            this.listInfo.Items.Add(item);
        }
    }
}
